import {defineStore} from "pinia";

const usePublicAccount = defineStore('publicAccount', {
    state: () => ({
        selectAc: '',
        selectid: '',
        menu: {},
        activeName: 'six',
    }),
    getters: {
        selectAccount(state) {
            return state.selectAc;
        },
        selectId(state) {
            return state.selectId;
        },
        getMenu(state){
            return state.menu;
        }
    },
    actions: {
        getMenus(){
            return this.menu || {'menu':{}};
        },
        getActiveName(){
          return this.activeName;
        },
        setActiveName(activeName){
            this.activeName = activeName;
        },
        setAccountMenu(menustr){
           if(menustr!=null &&menustr!=='') {
               this.menu = JSON.parse(menustr);
           }else{
               this.menu={};
           }
        },
        changeSelectAccount(name) {
            this.selectAc = name;
        },
        changeSelectId(id) {
            this.selectid = id;
        }
    },
    persist:{
        enabled: true,
        strategies: [
            {
                //key的名称
                key: 'publicaccount',
                //更改默认存储，我更改为localStorage
                storage: localStorage,
                // 可以选择哪些进入local存储，这样就不用全部都进去存储了
                // 默认是全部进去存储
                // paths: ['list']
            }
        ]
    }
})

export default usePublicAccount;
